package com.kyrie.security.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/***
 * 描述: 配置安全请求拦截器
 *
 * @author wuxiang
 * @date 2020-04-12 11:55
 */
@Configuration
public class InterceptorConfigurer implements WebMvcConfigurer {

    @Value("${shiro.anonMappings}")
    private String anonMappings;

    /**
     * 配置静态资源
     */
    /*public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
        super.addResourceHandlers(registry);
    }*/

    @Autowired
    private UltraViresInterceptor ultraViresInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用于排除拦截
        String[] excludePathPatterns = anonMappings.split(";");
        // 地址拦截器
        registry.addInterceptor(ultraViresInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathPatterns);
    }

}
